import intl from 'utils/intl';
import { getCurrentOrganizationId } from 'utils/utils';
import { CPAAS_PLATFORM } from 'utils/config';
import { EMAIL, PHONE } from 'utils/regExp';
var organizationId = getCurrentOrganizationId();
var treeDS = {
  autoQuery: true,
  selection: 'single',
  primaryKey: 'unitId',
  idField: 'unitId',
  parentField: 'parentUnitId',
  fields: [{
    name: 'unitId',
    type: 'string'
  }, {
    name: 'parentUnitId',
    type: 'string'
  }, {
    name: 'unitName',
    type: 'string'
  }],
  transport: {
    read: function read(config) {
      var url = "".concat(CPAAS_PLATFORM, "/v1/").concat(organizationId, "/units/plus/department");
      return {
        config: config,
        url: url,
        method: 'GET',
        params: {
          customizeUnitCode: 'CPFM.ORG_LIST.DEPARTMENT.BASIC'
        }
      };
    }
  }
};
var searchDepartmentDS = {
  fields: [{
    name: 'parentUnitIdLov',
    type: 'object',
    lovCode: 'CPFM.UNIT.COMPANY',
    lovPara: {
      tenantId: organizationId
    },
    label: intl.get('cpfm.organization.model.department.unitCompanyNameId').d('公司名称'),
    noCache: true
  }]
};
var createFormDS = {
  fields: [{
    name: 'unitCode',
    type: 'string',
    label: intl.get('cpfm.organization.model.department.unitCode').d('部门编码'),
    format: 'uppercase',
    required: true
  }, {
    name: 'unitName',
    type: 'intl',
    label: intl.get('cpfm.organization.model.department.unitName').d('部门名称'),
    maxLength: 120,
    required: true
  }, {
    name: 'unitTypeCode',
    type: 'string',
    label: intl.get('cpfm.organization.model.department.unitTypeCode').d('部门类型'),
    defaultValue: 'D'
  }, {
    name: 'parentUnitIdLov',
    type: 'object',
    lovCode: 'CPFM.PLUS.UNIT',
    lovPara: {
      tenantId: organizationId
    },
    label: intl.get('cpfm.organization.model.department.parentUnitId').d('上级组织'),
    noCache: true,
    ignore: 'always',
    required: true
  }, {
    name: 'parentUnitName',
    type: 'string',
    bind: 'parentUnitIdLov.unitName'
  }, {
    name: 'parentUnitId',
    type: 'string',
    bind: 'parentUnitIdLov.unitId'
  }, {
    name: 'unitCompanyId',
    type: 'string',
    bind: 'parentUnitIdLov.unitCompanyId'
  }, {
    name: 'orderSeq',
    type: 'number',
    min: 0,
    label: intl.get('cpfm.organization.model.department.orderSeq').d('排序号'),
    required: true
  }, {
    name: 'supervisorFlag',
    trueValue: 1,
    falseValue: 0,
    type: 'boolean',
    label: intl.get('cpfm.organization.model.department.supervisorFlag').d('主管组织'),
    defaultValue: 0
  }, {
    name: 'enabledFlag',
    trueValue: 1,
    falseValue: 0,
    type: 'boolean',
    label: intl.get('cpfm.organization.model.department.status').d('状态'),
    defaultValue: 1
  }, {
    name: 'tenantId',
    type: 'number',
    label: intl.get('cpfm.organization.model.department.tenantId').d('租户'),
    defaultValue: 0
  }],
  transport: {
    create: function create(config) {
      var url = "".concat(CPAAS_PLATFORM, "/v1/").concat(organizationId, "/units");
      return {
        config: config,
        url: url,
        method: 'POST',
        params: {
          customizeUnitCode: 'CPFM.ORG_LIST.DEPARTMENT.BASIC.EDIT'
        }
      };
    }
  }
};
var baseInfoDs = {
  fields: [{
    name: 'unitCode',
    type: 'string',
    label: intl.get('cpfm.organization.model.department.unitCode').d('部门编码')
  }, {
    name: 'unitName',
    type: 'string',
    label: intl.get('cpfm.organization.model.department.unitName').d('部门名称')
  }, {
    name: 'enabledFlag',
    trueValue: 1,
    falseValue: 0,
    type: 'boolean',
    label: intl.get('cpfm.organization.model.department.status').d('状态'),
    defaultValue: 1
  }, {
    name: 'parentUnitName',
    type: 'string',
    label: intl.get('cpfm.organization.model.department.parentUnitId').d('上级组织')
  }, {
    name: 'unitCompanyName',
    type: 'string',
    label: intl.get('cpfm.organization.model.department.company').d('公司')
  }]
};
var formDS = {
  fields: [{
    name: 'unitCode',
    type: 'string',
    label: intl.get('cpfm.organization.model.department.unitCode').d('部门编码'),
    format: 'uppercase',
    required: true
  }, {
    name: 'unitName',
    type: 'intl',
    maxLength: 120,
    label: intl.get('cpfm.organization.model.department.unitName').d('部门名称'),
    required: true
  }, {
    name: 'unitTypeCode',
    type: 'string',
    label: intl.get('cpfm.organization.model.department.unitTypeCode').d('部门类型'),
    defaultValue: 'D'
  }, {
    name: 'parentUnitIdLov',
    type: 'object',
    lovCode: 'CPFM.UNIT.DEPARTMENT',
    lovPara: {
      organizationId: organizationId
    },
    label: intl.get('cpfm.organization.model.department.parentUnitId').d('上级组织'),
    noCache: true,
    ignore: 'always',
    required: true
  }, {
    name: 'parentUnitName',
    type: 'string',
    bind: 'parentUnitIdLov.unitName'
  }, {
    name: 'parentUnitId',
    type: 'string',
    bind: 'parentUnitIdLov.unitId'
  }, {
    name: 'unitCompanyId',
    type: 'string'
  }, {
    name: 'orderSeq',
    type: 'number',
    min: 0,
    label: intl.get('cpfm.organization.model.department.orderSeq').d('排序号'),
    required: true
  }, {
    name: 'supervisorFlag',
    trueValue: 1,
    falseValue: 0,
    type: 'boolean',
    label: intl.get('cpfm.organization.model.department.primaryUnitTypeCode').d('主管组织'),
    defaultValue: 0
  }, {
    name: 'enabledFlag',
    trueValue: 1,
    falseValue: 0,
    type: 'boolean',
    label: intl.get('cpfm.organization.model.department.status').d('状态'),
    defaultValue: 1
  }, {
    name: 'tenantId',
    type: 'number',
    label: intl.get('cpfm.organization.model.department.tenantId').d('租户'),
    defaultValue: 0
  }],
  transport: {
    create: function create(config) {
      var url = "".concat(CPAAS_PLATFORM, "/v1/").concat(organizationId, "/units");
      return {
        config: config,
        url: url,
        method: 'POST',
        params: {
          customizeUnitCode: 'CPFM.ORG_LIST.COMPANY.DEPARTMENT.EDIT'
        }
      };
    }
  }
};
var employeeTableDS = {
  selection: false,
  dataKey: 'content',
  fields: [{
    name: 'employeeCode',
    type: 'string',
    label: intl.get('cpfm.organization.model.department.employeeCode').d('员工编码')
  }, {
    name: 'name',
    type: 'string',
    label: intl.get('cpfm.organization.model.department.name').d('姓名')
  }, {
    name: 'quickIndex',
    type: 'string',
    label: intl.get('cpfm.organization.model.department.quickIndex').d('快速检索')
  }, {
    name: 'phoneticize',
    type: 'string',
    label: intl.get('cpfm.organization.model.department.phoneticize').d('拼音')
  }, {
    name: 'email',
    type: 'string',
    label: intl.get('cpfm.organization.model.department.email').d('邮箱')
  }, {
    name: 'mobile',
    type: 'string',
    label: intl.get('cpfm.organization.model.department.mobile').d('手机号码')
  }, {
    name: 'joinDate',
    type: 'string',
    label: intl.get('cpfm.organization.model.department.joinDate').d('入职日期')
  }, {
    name: 'status',
    type: 'string',
    label: intl.get('cpfm.organization.model.department.employeeStatus').d('员工状态')
  }, {
    name: 'statusName',
    type: 'string',
    label: intl.get('cpfm.organization.model.department.statusName ').d('状态名称')
  }, {
    name: 'unitId',
    type: 'string',
    label: intl.get('cpfm.organization.model.department.unitId').d('部门ID')
  }, {
    name: 'unitName',
    type: 'string',
    label: intl.get('cpfm.organization.model.department.unitName').d('部门名称')
  }, {
    name: 'bornDate',
    type: 'string',
    label: intl.get('cpfm.organization.model.department.bornDate').d('出生日期')
  }, {
    name: 'certificateId',
    type: 'string',
    label: intl.get('cpfm.organization.model.department.certificateId').d('证件ID')
  }, {
    name: 'certificateType',
    type: 'string',
    label: intl.get('cpfm.organization.model.department.certificateType ').d('证件类型')
  }, {
    name: 'effectiveEndDate',
    type: 'string',
    label: intl.get('cpfm.organization.model.department.effectiveEndDate').d('证件失效日期')
  }, {
    name: 'effectiveStartDate',
    type: 'string',
    label: intl.get('cpfm.organization.model.department.effectiveStartDate').d('证件生效日期')
  }, {
    name: 'employeeId',
    type: 'string',
    label: intl.get('cpfm.organization.model.department.employeeId').d('员工表ID')
  }, {
    name: 'enabledFlag',
    type: 'string',
    label: intl.get('cpfm.organization.model.department.enabledFlag').d('启用状态')
  }, {
    name: 'gender',
    type: 'number',
    label: intl.get('cpfm.organization.model.department.gender').d('性别')
  }, {
    name: 'nameEn',
    type: 'string',
    label: intl.get('cpfm.organization.model.department.nameEn ').d('英文名')
  }, {
    name: 'phoneticize',
    type: 'string',
    label: intl.get('cpfm.organization.model.department.phoneticize').d('拼音')
  }, {
    name: 'positionId',
    type: 'number',
    label: intl.get('cpfm.organization.model.department.positionId').d('岗位ID')
  }, {
    name: 'primaryPositionFlag',
    type: 'number',
    label: intl.get('cpfm.organization.model.department.isPrimaryPositionFlag').d('主岗')
  }, {
    name: 'positionName',
    type: 'string',
    label: intl.get('cpfm.organization.model.department.positionName').d('岗位名称')
  }],
  transport: {
    read: function read(config) {
      var data = config.data,
          params = config.params;
      var unitId = data.unitId;
      var url = "".concat(CPAAS_PLATFORM, "/v1/").concat(organizationId, "/units/plus/user/").concat(unitId);
      return {
        params: params,
        url: url,
        method: 'GET'
      };
    }
  }
};
var employeeFormDS = {
  fields: [{
    name: 'employeeCode',
    type: 'string',
    label: intl.get('cpfm.organization.model.department.employeeCode').d('员工编码'),
    format: 'uppercase',
    required: true
  }, {
    name: 'name',
    type: 'string',
    label: intl.get('cpfm.organization.model.department.name').d('姓名'),
    required: true
  }, {
    name: 'gender',
    type: 'number',
    label: intl.get('cpfm.organization.model.department.gender').d('性别'),
    required: true
  }, {
    name: 'mobile',
    type: 'string',
    pattern: PHONE,
    label: intl.get('cpfm.organization.model.department.mobile').d('手机号码'),
    required: true
  }, {
    name: 'email',
    type: 'string',
    pattern: EMAIL,
    label: intl.get('cpfm.organization.model.department.email').d('邮箱'),
    required: true
  }, {
    name: 'departmentLov',
    type: 'object',
    lovCode: 'CPFM.PLUS.ALL.DEPARTMENT',
    lovPara: {
      tenantId: organizationId
    },
    ignore: 'always',
    noCache: true,
    label: intl.get('cpfm.organization.model.department.primaryUnitName').d('主岗部门名称'),
    required: true
  }, {
    name: 'unitId',
    type: 'string',
    bind: 'departmentLov.unitId'
  }, {
    name: 'unitName',
    type: 'string',
    bind: 'departmentLov.unitName'
  }, {
    name: 'positionId',
    type: 'string',
    lookupCode: 'LOV_POSITION',
    // cascadeMap: { unitId: 'unitId' },
    dynamicProps: function dynamicProps(_ref) {
      var record = _ref.record;
      return {
        disabled: !record.get('unitId')
      };
    },
    noCache: true,
    label: intl.get('cpfm.organization.model.department.position').d('岗位'),
    required: true
  }, {
    name: 'primaryPositionFlag',
    type: 'number',
    defaultValue: 1
  }, {
    name: 'status',
    type: 'string',
    label: intl.get('cpfm.organization.model.department.employeeStatus').d('员工状态'),
    required: true,
    defaultValue: 'ON'
  }, {
    name: 'enabledFlag',
    type: 'string',
    trueValue: '1',
    falseValue: '0',
    defaultValue: '1',
    required: true,
    label: intl.get('cpfm.organization.model.department.enabledFlag').d('启用状态')
  }]
};
var employeePositionFormDS = {
  fields: [{
    name: 'partTimeDepartmentLov',
    type: 'object',
    lovCode: 'CPFM.PLUS.ALL.DEPARTMENT',
    lovPara: {
      tenantId: organizationId
    },
    ignore: 'always',
    noCache: true,
    label: intl.get('cpfm.organization.model.department.primaryDepName').d('主岗部门名称')
  }, {
    name: 'unitId',
    type: 'string',
    bind: 'partTimeDepartmentLov.unitId'
  }, {
    name: 'unitName',
    type: 'string',
    bind: 'partTimeDepartmentLov.unitName'
  }, {
    name: 'partTimePositionId',
    type: 'string',
    lookupCode: 'LOV_POSITION',
    // cascadeMap: { unitId: 'unitId' },
    dynamicProps: function dynamicProps(_ref2) {
      var record = _ref2.record;
      return {
        disabled: !record.get('unitId')
      };
    },
    noCache: true,
    label: intl.get('cpfm.organization.model.department.partTimePosition').d('岗位')
  }, {
    name: 'primaryPositionFlag',
    type: 'number',
    defaultValue: 0
  }]
};
var employeeDetailFormDS = {
  fields: [{
    name: 'employeeCode',
    type: 'string',
    label: intl.get('cpfm.organization.model.department.employeeCode').d('员工编码')
  }, {
    name: 'name',
    type: 'string',
    label: intl.get('cpfm.organization.model.department.name').d('姓名')
  }, {
    name: 'gender',
    type: 'string',
    label: intl.get('cpfm.organization.model.department.gender').d('性别')
  }, {
    name: 'mobile',
    type: 'string',
    label: intl.get('cpfm.organization.model.department.mobile').d('手机号码')
  }, {
    name: 'email',
    type: 'string',
    label: intl.get('cpfm.organization.model.department.email').d('邮箱')
  }, {
    name: 'unitId',
    type: 'string',
    label: intl.get('cpfm.organization.model.department.unitId').d('部门ID')
  }, {
    name: 'unitName',
    type: 'string',
    label: intl.get('cpfm.organization.model.department.primaryUnitName').d('主岗部门名称')
  }, {
    name: 'positionName',
    type: 'string',
    label: intl.get('cpfm.organization.model.department.positionMing').d('岗位')
  }, {
    name: 'primaryPositionFlag',
    type: 'number',
    defaultValue: 1
  }, {
    name: 'status',
    type: 'string',
    label: intl.get('cpfm.organization.model.department.employeeStatus').d('员工状态')
  }, {
    name: 'enabledFlag',
    type: 'string',
    trueValue: '1',
    falseValue: '0',
    label: intl.get('cpfm.organization.model.department.enabledFlag').d('启用状态')
  }]
};
var positionTableDS = {
  selection: false,
  dataKey: 'content',
  fields: [{
    name: 'name',
    type: 'string',
    label: intl.get('cpfm.organization.model.department.departmentId').d('部门ID')
  }, {
    name: 'unitName',
    type: 'string',
    label: intl.get('cpfm.organization.model.department.unitName').d('部门名称')
  }, {
    name: 'enabledFlag',
    type: 'number',
    label: intl.get('cpfm.organization.model.department.enabledFlag').d('启用状态')
  }, {
    name: 'supervisorFlag',
    type: 'boolean',
    trueValue: 1,
    falseValue: 0,
    label: intl.get('cpfm.organization.model.department.supervisorDepFlag').d('主管岗位标记')
  }, {
    name: 'orderSeq',
    type: 'number',
    label: intl.get('cpfm.organization.model.department.orderSeq').d('排序号')
  }, {
    name: 'description',
    type: 'string',
    label: intl.get('cpfm.organization.model.department.description').d('岗位描述')
  }, {
    name: 'positionName',
    type: 'string',
    label: intl.get('cpfm.organization.model.department.positionName').d('岗位名称')
  }, {
    name: 'positionCode',
    type: 'string',
    label: intl.get('cpfm.organization.model.department.positionCode').d('岗位编码')
  }, {
    name: 'parentPositionId',
    type: 'string',
    label: intl.get('cpfm.organization.model.department.parentPositionId').d('父岗位ID')
  }, {
    name: 'unitId',
    type: 'string',
    label: intl.get('cpfm.organization.model.department.unitId').d('部门ID')
  }, {
    name: 'unitCompanyId',
    type: 'string',
    label: intl.get('cpfm.organization.model.department.unitCompanyId').d('公司ID')
  }, {
    name: 'positionId',
    type: 'string',
    label: intl.get('cpfm.organization.model.department.positionId').d('岗位ID')
  }],
  transport: {
    read: function read(config) {
      var data = config.data,
          params = config.params;
      var unitId = data.unitId;
      var url = "".concat(CPAAS_PLATFORM, "/v1/").concat(organizationId, "/positions/").concat(unitId);
      return {
        params: params,
        url: url,
        method: 'GET'
      };
    }
  }
};
export { treeDS, searchDepartmentDS, createFormDS, formDS, employeeTableDS, employeeFormDS, employeePositionFormDS, employeeDetailFormDS, positionTableDS, baseInfoDs };